import { http } from "@/utils/http";
import baseUrlProxy from "@/api/baseUrlProxy";

export type GeneratorItem = {
  coding: string;
  createTime: string;
  engine: string;
  remark: string;
  tableName: string;
};

export type ResultGeneratorList = {
  content: GeneratorItem[];
  totalElements: number;
};

export const getGeneratorList = (data?: object) => {
  return http.request<ResultGeneratorList>(
    "get",
    baseUrlProxy + "/api/generator/tables",
    {
      params: data
    }
  );
};
export const sync = (data?: object) => {
  return http.request<any>("post", baseUrlProxy + "/api/generator/sync", {
    data: data
  });
};
export const save = (data?: object) => {
  return http.request<any>("put", baseUrlProxy + "/api/generator", {
    data: data
  });
};

export const generator = (tableName, type, data?) => {
  return http.request<any>(
    "post",
    baseUrlProxy + "/api/generator/" + tableName + "/" + type,
    { params: data },
    { responseType: type === 2 ? "blob" : "" }
  );
};

export const getTableDetail = (tableName, data?) => {
  return http.request<any>("get", baseUrlProxy + "api/genConfig/" + tableName, {
    params: data
  });
};

export const update = data => {
  return http.request<any>("put", baseUrlProxy + "api/genConfig", {
    data: data
  });
};

export const getColumns = (data?) => {
  return http.request<any>("get", baseUrlProxy + "api/generator/columns", {
    params: data
  });
};
